package cn.com.huak.www.sell.controller;

import cn.com.huak.www.sell.dto.OrderDTO;
import cn.com.huak.www.sell.enums.ResultEnum;
import cn.com.huak.www.sell.exception.OrderException;
import cn.com.huak.www.sell.service.OrderMasterService;
import cn.com.huak.www.sell.service.PayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 支付
 * @author huak@wanggang
 * @date 2019/1/10 21:30
 */
@RequestMapping("/pay")
@Controller
@Slf4j
public class PayController {

    @Autowired
    private OrderMasterService orderMasterService;

    @Autowired
    private PayService payService;

    @RequestMapping("/create")
    public String create(@RequestParam("orderId") String orderId,
                         @RequestParam("returnUrl")String returnUrl){
        //1. 查询订单
        OrderDTO one = orderMasterService.findOne(orderId);
        if(null == one){
            log.error("【支付】当前的订单不存在...");
            throw new OrderException(ResultEnum.ORDER_NOT_EXIST);
        }

        //2. 创建订单
        payService.create(one);

        //3. 返回结果
        return "pay/create";
    }
}
